package examples

import (
	"fmt"
	"log"
	"time"

	"github.com/gin-gonic/gin"
)

type Person struct {
	Name     string    `form:"name" json:"name"`
	Address  string    `form:"address" json:"address"`
	Birthday time.Time `form:"birthday" json:"birthday" time_format:"2006-01-02" time_utc:"1"`
}

func JsonStart() {
	route := gin.Default()
	route.POST("/testing", startPage)
	route.Run(":8085")
}

func startPage(c *gin.Context) {
	var person Person
	// If `GET`, only `Form` binding engine (`query`) used.
	// If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`).
	// See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48
	var err error
	// 将请求体 绑定带到 person中
	if err = c.ShouldBind(&person); err == nil {
		fmt.Println("test。。。。。")
		log.Println(person.Name)
		log.Println(person.Address)
		log.Println(person.Birthday)
		c.String(200, "Success")
	} else {
		fmt.Printf("err.Error(): %v\n", err.Error())
		c.String(400, "error")
	}
}
